package org.example.netty.buf;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

/**
 * netty的缓冲区
 */
public class Demo1 {
    public static void main(String[] args) {
        final int length = 10;
        //创建缓冲
        ByteBuf byteBuf = Unpooled.buffer(length);
        //写入缓冲
        for (int i = 0; i < length; i++) {
            byteBuf.writeByte(i);
            //打印写入索引
            System.out.println("写入索引:" + byteBuf.writerIndex());
        }
        //读取缓冲
        for (int i = 0; i < length; i++) {
            System.out.println(byteBuf.readByte());
            //打印读取索引
            System.out.println("读取索引:" + byteBuf.readerIndex());
        }

    }
}
